package com.cssl.util;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class GoodsRandomKey {
    public static Set<String> extractRandomKeyword(String data) {
        // 将每行数据按逗号分割成关键词
        String[] keywords = data.split(",");
        // 随机选择一个关键词
        Random random = new Random();
        String randomKeyword = keywords[random.nextInt(keywords.length)].trim();
        // 返回包含随机选择关键词的集合
        return Collections.singleton(randomKeyword);
    }

    public static Set<String> poolResult(List<String> data){
        Set<String> uniqueKeywords = new HashSet<>();
        // 遍历数据列表
        for (String line : data) {
            Set<String> keywords = GoodsRandomKey.extractRandomKeyword(line);
            uniqueKeywords.addAll(keywords);
        }
        return uniqueKeywords;
    }
}
